/**
 * Created by baiguiren on 1/23/17.
 */

let count = 0;
let async = require('async');

async.during(
  function (callback) {
    //这里的第一个参数不是null的话，error会被传递为during最后一个参数的err参数
    return callback(null, count < 5);
  },
  function (callback) {
    count++;
    setTimeout(callback, 1000);
  },
  function (err) {
    // 5 seconds have passed
    //console.log(err);
    console.log(count);
  }
);